﻿//********************************************************************
// 
//  file:  frmChangePassword.cs
// 
//  (C) Copyright 2010, Diomede Corporation
//  All rights reserved
// 
//  Use, modification, and distribution is subject to   
//  the New BSD License (See accompanying file license.txt).
// 
//********************************************************************

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Diomede.SDK;

namespace Diomede.Explorer
{
    public partial class frmChangePassword : Form
    {
        public frmChangePassword()
        {
            InitializeComponent();
        }

        public frmChangePassword(ISession session)
        {
            InitializeComponent();
            Session = session;
        }

        public ISession Session { get; set; }

        private void btnChange_Click(object sender, EventArgs e)
        {
            if (!txtNewPassword.Text.Equals(txtConfirmNewPassword.Text, StringComparison.CurrentCulture))
            {
                MessageBox.Show(this, "New Password confirmation failed.", "Error");
                return;
            }
            paneLoading.Visible = true;
            paneLoading.Refresh();
            ISessionExecResult result = Session.ChangePassword(txtOldPassword.Text, txtNewPassword.Text);
            paneLoading.Visible = false;

            if (result.Status == Diomede.SDK.Enums.ExecutionResults.Success)
            {
                MessageBox.Show(this, "Password changed successfully.", "Change Password");
                Close();
            }
            else
            {
                MessageBox.Show(this, result.Message, "Change Password");
                return;
            }
        }
    }
}
